<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%
    String path = request.getContextPath();
			String basePath = request.getScheme() + "://"
					+ request.getServerName() + ":" + request.getServerPort()
					+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
<meta charset="utf-8" />
<title></title>

<meta name="description" content="overview & stats" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="static/css/bootstrap.min.css" />
<link rel="stylesheet" href="static/css/bootstrap-responsive.min.css" />
<link rel="stylesheet" href="static/css/font-awesome.min.css" />
<!--[if IE 7]><link rel="stylesheet" href="css/font-awesome-ie7.min.css" /><![endif]-->
<!--[if lt IE 9]><link rel="stylesheet" href="css/ace-ie.min.css" /><![endif]-->
<link rel="stylesheet" href="static/css/ace.min.css" />
<link rel="stylesheet" href="static/css/ace-responsive.min.css" />
<link rel="stylesheet" href="static/css/ace-skins.min.css" />

<!-- 
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
 -->
<script type="text/javascript" src="static/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
	window.jQuery
			|| document
					.write("<script src='js/jquery-1.9.1.min.js'>\x3C/script>");
</script>
<script type="text/javascript" src="static/js/bootstrap.min.js"></script>
<script type="text/javascript" src="static/js/ace-elements.min.js"></script>
<script type="text/javascript" src="static/js/ace.min.js"></script>
<script type="text/javascript" src="static/js/bootbox.min.js"></script>
<!--引入弹窗组件start-->
<script type="text/javascript" src="plugins/attention/zDialog/zDrag.js"></script>
<script type="text/javascript"
	src="plugins/attention/zDialog/zDialog.js"></script>
<!--引入弹窗组件end-->

<script type="text/javascript">
	$(top.hangge());

	//显示加载进度
	function jzts() {
		$("#jzts").show();
	}
	
	//新增
	function addAccount(organid){
		 //window.parent.jzts();
		top.jzts();
		var diag = new top.Dialog();
		diag.Drag=true;
		diag.Title ="新增";
		diag.URL = '<%=basePath%>/commercial/goAddCommercialAccount.do' + '?organid=' + organid;
		diag.Width = 400;
		diag.Height = 430;
		diag.CancelEvent = function() { //关闭事件
			if (diag.innerFrame.contentWindow.document
					.getElementById('centerOfMainFrame').style.display == 'none') {
				top.jzts();
				setTimeout("self.location.reload()", 100);
			}
			diag.close();
		};
		diag.show();
	}
	
	//修改
	function editAccount(accountid, organid){
		 //window.parent.jzts();
		top.jzts();
		var diag = new top.Dialog();
		diag.Drag=true;
		diag.Title ="修改";
		diag.URL = '<%=basePath%>/commercial/goEditCommercialAccount.do?accountid=' + accountid + '&organid=' + organid;
		diag.Width = 400;
		diag.Height = 430;
		diag.CancelEvent = function() { //关闭事件
			if (diag.innerFrame.contentWindow.document
					.getElementById('centerOfMainFrame').style.display == 'none') {
				top.jzts();
				setTimeout("self.location.reload()", 100);
			}
			diag.close();
		};
		diag.show();
	}
	
	//删除
	function delAccount(accountid, msg){
		bootbox.confirm("确定要删除["+msg+"]吗?", function(result) {
			if(result) {
				var url = "<%=basePath%>/commercial/deleteCommercialAccount.do?accountid=" + accountid + "&tm="+ new Date().getTime();
				$.get(url,function(data){
					if(data=="success"){
						top.jzts();
						setTimeout("self.location.reload()", 100);
					}
				});
			}
		});
	}
	
	//批量操作
	function makeAll(msg){
		bootbox.confirm(msg, function(result) {
			if(result) {
				var str = '';
				var emstr = '';
				var phones = '';
				for(var i=0;i < document.getElementsByName('ids').length;i++)
				{
					  if(document.getElementsByName('ids')[i].checked){
					  	if(str=='') str += document.getElementsByName('ids')[i].value;
					  	else str += ',' + document.getElementsByName('ids')[i].value;
					  	
					  	if(emstr=='') emstr += document.getElementsByName('ids')[i].id;
					  	else emstr += ';' + document.getElementsByName('ids')[i].id;
					  	
					  	if(phones=='') phones += document.getElementsByName('ids')[i].alt;
					  	else phones += ';' + document.getElementsByName('ids')[i].alt;
					  }
				}
				if(str==''){
					bootbox.dialog("您没有选择任何内容!", 
						[
						  {
							"label" : "关闭",
							"class" : "btn-small btn-success",
							"callback": function() {
								//Example.show("great success");
								}
							}
						 ]
					);
					
					$("#zcheckbox").tips({
						side:3,
			            msg:'点这里全选',
			            bg:'#AE81FF',
			            time:8
			        });
					
					return;
				}else{
					if(msg == '确定要删除选中的数据吗?'){
						$.ajax({
							type: "POST",
							url: 'commercial/deleteAllAccount.do?tm='+new Date().getTime(),
					    	data: {accountids:str},
							dataType:'json',
							//beforeSend: validateData,
							cache: false,
							success: function(data){
								 $.each(data.list, function(i, list){
									 	top.jzts();
										setTimeout("self.location.reload()", 100);
								 });
							}
						});
					}
				}
			}
		});
	}
</script>
</head>

<body>
	<div class="container-fluid" id="main-container">
		<div id="breadcrumbs">
			<ul class="breadcrumb">
				<li><i class="icon-home"></i> <a>商户管理</a> <span class="divider">
						<i class="icon-angle-right"></i>
				</span></li>
				<li class="active">账户管理</li>
			</ul>
			<!--.breadcrumb-->
		</div>
		<!--#breadcrumbs-->
		<div id="page-content">
			<div class="row-fluid">
				<div class="row-fluid">
					<table id="table_report"
						class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th class="center">
									<label><input type="checkbox" id="zcheckbox" /><span class="lbl"></span></label>
								</th>
								<th class="center">序号</th>
								<th>账户名称</th>
								<th>账户类型</th>
								<th>账户号码</th>
								<th>备注</th>
								<th style="width: 155px;" class="center">操作</th>
							</tr>
						</thead>
						<c:choose>
							<c:when test="${not empty accountList}">
								<c:forEach items="${accountList}" var="var" varStatus="vs">
									<tr>
										<td class='center' style="width: 30px;">
											<label><input type='checkbox' name='ids' value="${var.accountid }" id="${var.accountid }" alt="${var.accountname }"/><span class="lbl"></span></label>
										</td>
										<td class='center' style="width: 30px;">${vs.index+1}</td>
										<td id="accountTd${var.accountid }">${var.accountname }</td>
										<td>${var.accounttypename }</td>
										<td>${var.accountno }</td>
										<td>${var.remark }</td>
										<td style="width: 155px;">
											<a class='btn btn-mini btn-info' title="编辑" onclick="editAccount('${var.accountid }','${pageData.organId }');"> <i class='icon-edit'></i></a> 
											<a class='btn btn-mini btn-danger' title="删除" onclick="delAccount('${var.accountid }', ${var.accountname });"> <i class='icon-trash'></i> </a>
										</td>
									</tr>
								</c:forEach>
								<!-- <tr>
									<td colspan="100" class="center">您无权查看</td>
								</tr> -->
							</c:when>
							<c:otherwise>
								<tr>
									<td colspan="100" class="center">没有相关数据</td>
								</tr>
							</c:otherwise>
						</c:choose>
					</table>

					<div class="page-header position-relative">
						<table style="width:100%;">
							<tr>
								<td style="vertical-align:top;">
									<a class="btn btn-small btn-success" onclick="addAccount('${pageData.organid }');">新增</a>
									<a title="批量删除" class="btn btn-small btn-danger" onclick="makeAll('确定要删除选中的数据吗?');" ><i class='icon-trash'></i></a>
								</td>
								<td style="vertical-align:top;"><div class="pagination" style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div></td>
							</tr>
						</table>
					</div>
				</div>
				<!-- PAGE CONTENT ENDS HERE -->
			</div>
			<!--/row-->

		</div>
		<!--/#page-content-->
	</div>
	<!--/.fluid-container#main-container-->
</body>
</html>